#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

import wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp

from model.ClassM import ClassState
from model.CourseM import Course
from model.LectureM import Lecture
from model.TopicM import Topic

class MyHandler(webapp.RequestHandler):
    
    def get(self):
        db.delete(db.Query(Course))
        db.delete(db.Query(Lecture))
        db.delete(db.Query(Topic))
        db.delete(db.Query(ClassState))

        # courses
        course1 = Course(name="Photography - beginners")
        course1.put()
#        course2 = Course(name="Photography - Advanced")
#        course2.put()
#        course3 = Course(name="PhotoShop - Advanced image manipulation")
#        course3.put()

        #lecture
        lecture1 = Lecture(index=1, name = "Class I: Introduction", course = course1)
        lecture1.put()
        lecture2 = Lecture(index=2, name = "Class II: Field Depth/Focal length", course = course1)
        lecture2.put()
        lecture3 = Lecture(index=3, name = "Class III: Tips and tricks on outdoor photography", course = course1)
        lecture3.put()
#        lecture4 = Lecture(index=4, name = "Class IV: Rothshield Avenue - photoshoot", course = course1)
#        lecture4.put()
#        lecture5 = Lecture(index=5, name = "Class V: Work review", course = course1)
#        lecture5.put()
#        lecture6 = Lecture(index=6, name = "Class VI: Jaffa port city - photoshoot", course = course1)
#        lecture6.put()
#        lecture7 = Lecture(index=7, name = "Class VII: Course conclusion - student presentations", course = course1)
#        lecture7.put()

#        lecture8 = Lecture(index=1, name = "Artistic perception:  standard 1", course = course2)
#        lecture8.put()
#        lecture9 = Lecture(index=2, name = "Creative expression: standard 2", course = course2)
#        lecture9.put()
#        lecture10 = Lecture(index=3, name = "Historical and cultural context: standard 3", course = course2)
#        lecture10.put()
#        lecture11 = Lecture(index=4, name = "Aesthetic valuing: standard 4", course = course2)
#        lecture11.put()
#        lecture12 = Lecture(index=5, name = "Connections, relationships, and applications:  standard 5", course = course2)
#        lecture12.put()
#        lecture13 = Lecture(index=6, name = "Computer image manipulation: standard 6", course = course2)
#        lecture13.put()

#        lecture14 = Lecture(index=1, name = "Lesson 1: INTRODUCTION TO ADOBE PHOTOSHOP CS5", course = course3)
#        lecture14.put()
#        lecture15 = Lecture(index=2, name = "Lesson 2: Getting Started with Photoshop", course = course3)
#        lecture15.put()
#        lecture16 = Lecture(index=3, name = "Lesson 3: Working with Images", course = course3)
#        lecture16.put()



        #topics
        topic1 = Topic(index=1, name="First topic lecture 1", time=30, lecture = lecture1)
        topic1.put()
        topic2 = Topic(index=2, name="second topic lecture 1", time=30, lecture = lecture1)
        topic2.put()
        topic3 = Topic(index=1, name="First topic lecture 2", time=30, lecture = lecture2)
        topic3.put()
        topic4 = Topic(index=2, name="second topic lecture 2", time=30, lecture = lecture2)
        topic4.put()
        topic5 = Topic(index=1, name="First topic lecture 3", time=30, lecture = lecture3)
        topic5.put()
        topic6 = Topic(index=2, name="second topic lecture 3", time=30, lecture = lecture3)
        topic6.put()

#        #questions
#        question1 = Question(name = "Insects", text="what is an insect?", answers=["nothing", "something", "someone"], lecture = lecture1)
#        question1.put()
#        question2 = Question(name = "photoshop", text="what is photoshop?", answers=["nothing", "something", "someone"], lecture = lecture1)
#        question2.put()
#
#        question3 = Question(name = "stuff", text="what is stuff?", answers=["nothing", "something", "someone"], lecture = lecture3)
#        question3.put()
#        question4 = Question(name = "computers", text="what is a computer?", answers=["nothing", "something", "someone"], lecture = lecture3)
#        question4.put()

#        #questionanswers
#        qa1 = QuestionAnswer(question= question1, answer="something", userid=0)
#        qa1.put()
#        qa2 = QuestionAnswer(question= question1, answer="something", userid=1)
#        qa2.put()
#        qa3 = QuestionAnswer(question= question1, answer="nothing", userid=2)
#        qa3.put()
#
#        qa4 = QuestionAnswer(question= question2, answer="something", userid=0)
#        qa4.put()
#        qa5 = QuestionAnswer(question= question2, answer="something", userid=1)
#        qa5.put()
#        qa6 = QuestionAnswer(question= question2, answer="nothing", userid=2)
#        qa6.put()
        
        classState1 = ClassState(lecture = lecture1, currentTopic = topic1, isQuizOn = False)
        classState1.put()
        classState2 = ClassState(lecture = lecture2, currentTopic = topic3, isQuizOn = False)
        classState2.put()

        self.response.out.write("success")
        # user = users.get_current_user()
        # if not user:
        #     self.response.out.write("not logged in")
        # else:
        #     self.response.out.write("welcome, " + user.nickname())

def main():
    app = webapp.WSGIApplication([
        (r'.*', MyHandler)], debug=True)
    wsgiref.handlers.CGIHandler().run(app)

if __name__ == "__main__":
    main()